
// 路径
import path from "path-browserify";

// 商品数据类型
type ProductItem = {
    id: number;
    name: string;
    price?: number;
    url: string,
    img: string,
}

// 商品类别类型
type ProductCategory = {
    title: string,
    categoryId: number;
    items: ProductItem[]
}

// 商品图片根路径
const productImgRootPath = '/img/product_list/'

// 商品类别信息
const productCategoryInfo: { [key: string]: ProductCategory } = {
    "白牡丹": {
        title: "白牡丹",
        categoryId: 1,
        items: [
            { id: 1, name: "茶百道", price: 20, url: "https://www.example.com/tea1", img: '2.png' }
        ]
    },
    "正山小种": {
        title: "正山小种",
        categoryId: 2,
        items: [
            { id: 2, name: "茶百道", price: 30, url: "https://www.example.com/tea2", img: '1.png' }
        ]
    },
    "贡眉": {
        title: "贡眉",
        categoryId: 3,
        items: [
            { id: 3, name: "茶百道", price: 40, url: "https://www.example.com/tea3", img: '2.png' }
        ]
    }
}

// 对商品img路径进行拼接
Object.values(productCategoryInfo).forEach(categortInfo => {
    categortInfo.items.forEach(item => item.img = path.join(productImgRootPath, item.img))
})

// 商品类别列表
export const productCategoryList: ProductCategory[] = [
    {
        title: "全部",
        categoryId: 0,
        items: Object.values(productCategoryInfo).flatMap(item => item.items)
    },
    ...Object.values(productCategoryInfo)
]


